﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProgramMain.Framework;

namespace ProgramMain.Classifiers
{
    public partial class CurveElementTypeList : ProgramMain.Framework.BaseGridListCtl
    {
        public CurveElementTypeList()
        {
            InitializeComponent();
        }

        private Nullable<int> m_CurveElementKindID = new Nullable<int>();
        public Nullable<int> CurveElementKindID
        {
            get
            {
                return m_CurveElementKindID;
            }
            set
            {
                if (m_CurveElementKindID != value)
                {
                    m_CurveElementKindID = value;
                    if(value == 3)
                    {
                        colModuleCount.Caption = "Кол-во портов";
                        colFibrePerModule.Visible = false;
                      //  colFibrePerModule.VisibleIndex = -1;
                        colFibreCount.Visible = false;
                      //  colFibreCount.VisibleIndex = -1;
                    }
                    else
                    {
                        colModuleCount.Caption = "Кол-во модулей";
                        colFibrePerModule.Visible = true;
                        //  colFibrePerModule.VisibleIndex = -1;
                        colFibreCount.Visible = true;
                        //  colFibreCount.VisibleIndex = -1;
                    }
                    DBRead();
                }
            }
        }

        protected override void LoadData()
        {
            //прочитать данные из базы и заполнить датасет
            if (m_CurveElementKindID.HasValue)
            {
                this.curveElementTypesTableAdapter.SelectCommandTimeout = ProgramMain.Properties.Settings.Default.LongQueryTimeout;
                this.curveElementTypesTableAdapter.Fill(this.simpleOpticNetDB.CurveElementTypes, m_CurveElementKindID);
            }
            else
            {
                this.simpleOpticNetDB.CurveElementTypes.Clear();
            }
            UpdateStatusText(this.simpleOpticNetDB.CurveElementTypes);
        }

        protected override void UpdateData()
        {
            //внести изменения в базу
            this.curveElementTypesTableAdapter.SetUpdateTimeout = ProgramMain.Properties.Settings.Default.LongQueryTimeout;
            this.curveElementTypesTableAdapter.Update(this.simpleOpticNetDB.CurveElementTypes);
            UpdateStatusText(this.simpleOpticNetDB.CurveElementTypes);
        }

        override protected BaseModalDetailCtl CreateDetailDialog(BaseModalDetailCtl.ShowModeTypes pShowMode)
        {
            CurveElementTypeDetail frm = new CurveElementTypeDetail();
            
            if (m_CurveElementKindID.HasValue)
                frm.CurveElementKindID = m_CurveElementKindID;
            
            return frm;
        }

        public override BaseSecurity.SuperBool CheckSecurityAction(BaseSecurity.SecurityActionType ActionType, bool ShowWarning)
        {
            if (BaseSecurity.CheckSecuritySuperAction())
            {
                return BaseSecurity.SuperBool.True;
            }

            return BaseSecurity.SuperBool.False;
        }

       
    }
}
